package com.Semaphore;


import java.util.concurrent.Semaphore;

/**
 * Created by apple on 17/9/29.
 */
public class Task extends Thread {
    private int n;
    private Semaphore sm;

    public Task(int n, Semaphore sm){
        this.n = n;
        this.sm = sm;
    }
    @Override
    public void run() {
        try {
            sm.acquire();
            System.out.println("工人"+this.n+"占用一个机器");
            Thread.sleep(2000);
            System.out.println("释放");
            sm.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
